//
//  BN_MINE_MedalAndCommentViewController.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-5-23.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_MINE_MedalAndCommentViewController.h"
#define PATH_DOC_CHILMEDAL [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"ChilMedal"]

static int COUNT_ = 0;

@interface BN_MINE_MedalAndCommentViewController () {
    NSString *chilIdMedal_;
    NSString *chilIdComment_;
    
    NSArray *itmeNameArr_;
    NSArray *itemImgArr_;
    UIImageView *upDownImgView;
    
    BN_MedalAndCommentView *medalAndCommentView_;
    BN_MyInfoHelper *myInfoHelper_;
    BN_Mine_TeacherBrowseCommentData *browseCommentData_;
    CPTextDelegate *cpTextDelegate_;
}

@end

@implementation BN_MINE_MedalAndCommentViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    // UI+64
    if (IOS7) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // UI
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"houtui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBeforeVc)];
    self.navigationItem.leftBarButtonItem = leftItem;
    medalAndCommentView_ = [[[NSBundle mainBundle]loadNibNamed:@"BN_MedalAndCommentView" owner:nil options:nil]objectAtIndex:0];
    medalAndCommentView_.frame = CGRectMake((SCREEN_WIDTH-180)/2, 0, 180, 26);
    medalAndCommentView_.layer.cornerRadius = 12;
    medalAndCommentView_.layer.masksToBounds = YES;
    [medalAndCommentView_ loadBtnView];
    medalAndCommentView_.backgroundColor = [UIColor clearColor];
    self.navigationItem.titleView = medalAndCommentView_;
    
    // 风火轮
    [self viewLoadHintView];
    
    itmeNameArr_ = @[@"全勤",@"懂礼貌",@"讲卫生",@"不挑食",@"爱思考",@"守纪律"];
    itemImgArr_ = @[@"quanqingdianji",@"donglimaodianji",@"jiangweishengdianji",@"butiaoshidianji",@"aisikaodianji",@"soujilvdianji"];
    
    // 勋章
    // 获取应用程序沙盒的Documents目录
    chilIdMedal_ = [@"chilIdMedal_" stringByAppendingFormat:@"%@",self.chilIdStr];
    chilIdMedal_ = [chilIdMedal_ stringByAppendingString:@".plist"];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:[PATH_DOC_CHILMEDAL stringByAppendingPathComponent:chilIdMedal_]]) {
        [fileManager createDirectoryAtPath:PATH_DOC_CHILMEDAL withIntermediateDirectories:YES attributes:nil error:nil];
        NSString *filename = [PATH_DOC_CHILMEDAL stringByAppendingPathComponent:chilIdMedal_];
        NSArray *plistArr = @[@{@"sendTime": @"",@"operateNumb":@"1"},@{@"sendTime": @"",@"operateNumb":@"1"},@{@"sendTime": @"",@"operateNumb":@"1"},@{@"sendTime": @"",@"operateNumb":@"1"},@{@"sendTime": @"",@"operateNumb":@"1"},@{@"sendTime": @"",@"operateNumb":@"1"}];
        [plistArr writeToFile:filename atomically:YES];
    }
    NSString *filename = [PATH_DOC_CHILMEDAL stringByAppendingPathComponent:chilIdMedal_];
    self.medalPlistArr = [[NSMutableArray alloc]initWithContentsOfFile:filename];
    
    // helper
    myInfoHelper_ = [[BN_MyInfoHelper alloc]init];
    [self performSelectorInBackground:@selector(requestNetDataForMedal) withObject:nil];
    
    // UI
    self.greenColor = APP_OBJECT_GREEN_COLOR;
    self.view.backgroundColor = APP_OBJECT_GRAY_COLOR;
    self.cpTextView.hidden = YES;
}

// 判断本地存放的时间和当前时间是否差7天
- (void)dealTimePostWeek:(NSMutableArray *)arr {
    for (int i = 0; i < arr.count; i++) {
        NSString *timeStr = arr[i][@"sendTime"];
        if ([timeStr isEqualToString:@""]) {
            [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"MINE_TEACHER_IS_SENDMEDAL"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }else {
            // 现在的时间和服务器的记录时间
            NSInteger diffDay = -([self dataSpace:timeStr]);
            if (diffDay <=7) {
                [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"MINE_TEACHER_IS_SENDMEDAL"];
                [[NSUserDefaults standardUserDefaults]synchronize];
            }else {
                [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"MINE_TEACHER_IS_SENDMEDAL"];
                [[NSUserDefaults standardUserDefaults]synchronize];
                
                //删除待删除的文件
                NSFileManager *fileManager = [NSFileManager defaultManager];
                [fileManager removeItemAtPath:PATH_DOC_CHILMEDAL error:nil];
            }
            break;
        }
    }
}

- (void)toGroupView {
    // Action
    [medalAndCommentView_.toMedalBtn addTarget:self action:@selector(medalAction:) forControlEvents:UIControlEventTouchUpInside];
    [medalAndCommentView_.toCommentBtn addTarget:self action:@selector(commentAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // UIScrollView
    self.medalAndCommentScrollView = [[UIScrollView alloc]init];

    switch (MAIN_VERSION) {
        case 6:
            self.medalAndCommentScrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-44);
            break;
        default:
            
            self.medalAndCommentScrollView.frame = CGRectMake(0, 64, SCREEN_WIDTH, FULLSCREEN_HEIGHT-64);
            self.medalAndCommentScrollView.contentSize = CGSizeMake(320*2, FULLSCREEN_HEIGHT-64);
            break;
    }
    
    self.medalAndCommentScrollView.pagingEnabled = YES;
    self.medalAndCommentScrollView.directionalLockEnabled = YES;
    self.medalAndCommentScrollView.delegate = self;
    self.medalAndCommentScrollView.showsHorizontalScrollIndicator = NO;
    self.medalAndCommentScrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.medalAndCommentScrollView];
    [self.medalAndCommentScrollView addSubview:[self medalView]];
    [self.medalAndCommentScrollView addSubview:[self commentView]];
}

#pragma mark
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSLog(@"%f",scrollView.contentOffset.x);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    // 移除键盘
    if (scrollView.contentOffset.x<160) {
        [self.cpTextView resignFirstResponder];
        // 移除右侧navgationBar
        self.navigationItem.rightBarButtonItem = nil;
        self.commentTableView.hidden = YES;
        upDownImgView.image = [UIImage imageNamed:@"comment_jiantou_up"];

        [medalAndCommentView_.toMedalBtn setBackgroundColor:[UIColor whiteColor]];
        [medalAndCommentView_.toMedalBtn setTitleColor:self.greenColor forState:UIControlStateNormal];
        [medalAndCommentView_.toCommentBtn setBackgroundColor:self.greenColor];
        [medalAndCommentView_.toCommentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        medalAndCommentView_.toCommentBtn.backgroundColor = [UIColor clearColor];
        medalAndCommentView_.toCommentBtn.frame = CGRectMake(102, 0, 100, 26);
        [medalAndCommentView_.toCommentBtn setTitle:@"  写评语" forState:UIControlStateNormal];
    
    }else {
        // 添加右侧navgationBar
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(sendCommentAction)];
        self.navigationItem.rightBarButtonItem = rightItem;
        BOOL isOperate = [[NSUserDefaults standardUserDefaults]boolForKey:@"MINE_TEACHER_IS_SENDMEDAL"];
        if (isOperate) {
            self.navigationItem.rightBarButtonItem.enabled = NO;
        }else {
            self.navigationItem.rightBarButtonItem.enabled = YES;
        }
        
        medalAndCommentView_.toCommentBtn.backgroundColor = [UIColor whiteColor];
        [medalAndCommentView_.toCommentBtn setTitleColor:self.greenColor forState:UIControlStateNormal];
        [medalAndCommentView_.toCommentBtn setTitle:@"      写评语" forState:UIControlStateNormal];
        medalAndCommentView_.toCommentBtn.frame = CGRectMake(85, 0, 100, 26);
        
        [medalAndCommentView_.toCommentBtn setBackgroundImage:[UIImage imageNamed:@"daohanglan"] forState:UIControlStateNormal];
        [medalAndCommentView_.toMedalBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        medalAndCommentView_.toMedalBtn.backgroundColor = [UIColor clearColor];
        [medalAndCommentView_.toCommentBtn setBackgroundImage:nil forState:UIControlStateNormal];
    }
}

#pragma mark 网络请求
- (void)requestNetDataForMedal {
    __weak typeof(self) weakSelf = self;
    NSString *childId = self.chilIdStr;
    [myInfoHelper_ queryMedalTypeListForChildId:childId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf cancelHintView];
        }else{
            weakSelf.cpTextView.hidden = NO;
            [weakSelf cancelHintView];
            
            COUNT_ = 0;
            weakSelf.netArr = (NSArray *)result;
            
            // 网络读取，plist修改时间
            for (int i = 0; i < weakSelf.netArr.count; i++) {
                NSString *filename = [PATH_DOC_CHILMEDAL stringByAppendingPathComponent:chilIdMedal_];
                NSString *sendTimeStr = weakSelf.netArr[i][@"medaDate"];
                if (![sendTimeStr isEqual:[NSNull null]]) {
                    sendTimeStr = [sendTimeStr stringByReplacingOccurrencesOfString:@" " withString:@""];
                    sendTimeStr = [sendTimeStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
                    sendTimeStr = [sendTimeStr stringByReplacingOccurrencesOfString:@":" withString:@""];
                    sendTimeStr = [sendTimeStr stringByReplacingOccurrencesOfString:@"." withString:@""];
                    sendTimeStr = [sendTimeStr substringWithRange:NSMakeRange(0, 14)];
                    [self.medalPlistArr[i] setObject:sendTimeStr forKey:@"sendTime"];
                    [self.medalPlistArr writeToFile:filename atomically:YES];
                }
            }
            
            [weakSelf dealTimePostWeek:self.medalPlistArr];
            [weakSelf toGroupView];
        }
    }];
}

#pragma mark
#pragma mark 勋章和评论View
- (UIView *)medalView {
    UIView *medalView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FULLSCREEN_HEIGHT-64)];
    medalView.backgroundColor = APP_OBJECT_GRAY_COLOR;

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            UIButton *itmeBtn = [[UIButton alloc]initWithFrame:CGRectMake(20+80*j+20*j, 24+80*i+40*i, 80, 80)];
            itmeBtn.tag = COUNT_;
            [itmeBtn setImage:[UIImage imageNamed:itemImgArr_[COUNT_]] forState:UIControlStateNormal];
            BOOL isOperate = [[NSUserDefaults standardUserDefaults]boolForKey:@"MINE_TEACHER_IS_SENDMEDAL"];
            if (!isOperate) {
                itmeBtn.enabled = YES;
                itmeBtn.alpha = 1;
                [itmeBtn addTarget:self action:@selector(sendMedalAction:) forControlEvents:UIControlEventTouchUpInside];
            }else {
                itmeBtn.enabled = NO;
                itmeBtn.alpha = 0.65;
            }
            
            UILabel *itmeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20+80*j+20*j, 14+80+10+80*i+40*i, 80, 14)];
            itmeNameLabel.backgroundColor = [UIColor clearColor];
            itmeNameLabel.textAlignment = NSTextAlignmentCenter;
            itmeNameLabel.font = [UIFont systemFontOfSize:14.0f];
            if (!self.netArr) {
                itmeNameLabel.text = itmeNameArr_[COUNT_];
            }else {
                itmeNameLabel.text = self.netArr[COUNT_][@"medaName"];
            }
       
            itmeNameLabel.tag = COUNT_;
            
            COUNT_++;
            [medalView addSubview:itmeBtn];
            [medalView addSubview:itmeNameLabel];
        }
    }
    return medalView;
}

- (UIView *)commentView {
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(browseFullText:) name:@"KMINE_TEACHER_BROWSE_COMMENT" object:nil];
    
    // 文字框
    UIView *commentView = [[UIView alloc]initWithFrame:CGRectMake(320, 0, SCREEN_WIDTH, FULLSCREEN_HEIGHT-64)];
    commentView.backgroundColor = APP_OBJECT_GRAY_COLOR;
    self.cpTextView.frame = CGRectMake(0, 20, SCREEN_WIDTH, 150);
    self.cpTextView.placeholder = @"  说点什么吧...";
    if (!cpTextDelegate_) {
        cpTextDelegate_ = [[CPTextDelegate alloc]init];
    }
    [cpTextDelegate_ toHideCommentList:^(BOOL ishide) {
        if (ishide) {
            self.commentTableView.hidden = YES;
            upDownImgView.image = [UIImage imageNamed:@"comment_jiantou_up"];
        }
    }];
    self.cpTextView.delegate = cpTextDelegate_;
    [commentView addSubview:self.cpTextView];
    
    
    // 历史记录
    UIView *lookBeforeView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.cpTextView.frame)+20, SCREEN_WIDTH, 25)];
    lookBeforeView.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
    lookBeforeView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lookBeforeInfoAction)];
    [lookBeforeView addGestureRecognizer:tapped];
    
    UILabel *lookBeforeLabel = [[UILabel alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-100)/2, 0, 100, 25)];
    lookBeforeLabel.text = @"查看以往发送";
    lookBeforeLabel.font = [UIFont systemFontOfSize:14.0f];
    lookBeforeLabel.backgroundColor = [UIColor clearColor];
    lookBeforeLabel.textColor = [UIColor whiteColor];
    [lookBeforeView addSubview:lookBeforeLabel];
    [commentView addSubview:lookBeforeView];
    
    upDownImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lookBeforeLabel.frame)-20, -2, 25, 25)];
    upDownImgView.image = [UIImage imageNamed:@"comment_jiantou_up"];
    [lookBeforeView addSubview:upDownImgView];
    
    // 列表
    self.commentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(lookBeforeView.frame)+1, SCREEN_WIDTH, FULLSCREEN_HEIGHT-CGRectGetMaxY(lookBeforeView.frame)-64)];
    [self setExtraCellLineHidden:self.commentTableView];
    if ([self.commentTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.commentTableView setSeparatorInset:UIEdgeInsetsZero];
    }
    [commentView addSubview:self.commentTableView];
    self.commentTableView.hidden = YES;

    return commentView;
}

- (void)setExtraCellLineHidden:(UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = APP_OBJECT_GRAY_COLOR;
    [tableView setTableFooterView:view];
}

#pragma mark
#pragma mark Action 

- (void)medalAction:(id)sender {
    CGPoint position = CGPointMake(0, 0);
    [_medalAndCommentScrollView setContentOffset:position animated:YES];
    
    [self.cpTextView resignFirstResponder];
    // 移除右侧navgationBar
    self.navigationItem.rightBarButtonItem = nil;
    self.commentTableView.hidden = YES;
    upDownImgView.image = [UIImage imageNamed:@"comment_jiantou_up"];
    
    [medalAndCommentView_.toMedalBtn setBackgroundColor:[UIColor whiteColor]];
    [medalAndCommentView_.toMedalBtn setTitleColor:self.greenColor forState:UIControlStateNormal];
    [medalAndCommentView_.toCommentBtn setBackgroundColor:self.greenColor];
    [medalAndCommentView_.toCommentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    medalAndCommentView_.toCommentBtn.backgroundColor = [UIColor clearColor];
    medalAndCommentView_.toCommentBtn.frame = CGRectMake(102, 0, 100, 26);
    [medalAndCommentView_.toCommentBtn setTitle:@"  写评语" forState:UIControlStateNormal];
}

- (void)commentAction:(id)sender {
    CGPoint position = CGPointMake(320, 0);
    [_medalAndCommentScrollView setContentOffset:position animated:YES];
    
    // 添加右侧navgationBar
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(sendCommentAction)];
    self.navigationItem.rightBarButtonItem = rightItem;
    BOOL isOperate = [[NSUserDefaults standardUserDefaults]boolForKey:@"MINE_TEACHER_IS_SENDMEDAL"];
    if (isOperate) {
        self.navigationItem.rightBarButtonItem.enabled = NO;
    }else {
        self.navigationItem.rightBarButtonItem.enabled = YES;
    }
    
    medalAndCommentView_.toCommentBtn.backgroundColor = [UIColor whiteColor];
    [medalAndCommentView_.toCommentBtn setTitleColor:self.greenColor forState:UIControlStateNormal];
    [medalAndCommentView_.toCommentBtn setTitle:@"      写评语" forState:UIControlStateNormal];
    medalAndCommentView_.toCommentBtn.frame = CGRectMake(85, 0, 100, 26);
    
    [medalAndCommentView_.toCommentBtn setBackgroundImage:[UIImage imageNamed:@"daohanglan"] forState:UIControlStateNormal];
    [medalAndCommentView_.toMedalBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    medalAndCommentView_.toMedalBtn.backgroundColor = [UIColor clearColor];
    [medalAndCommentView_.toCommentBtn setBackgroundImage:nil forState:UIControlStateNormal];
}

- (void)sendCommentAction {
    [self.cpTextView resignFirstResponder];
    NSString *childId = self.chilIdStr;
    NSString *evalCont = self.cpTextView.text;
    __weak typeof(self) weakSelf = self;
    [myInfoHelper_ sendEvaLInfoForChildId:childId evalCont:evalCont completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [LZCHINT title:@"发送失败" type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
        }else{
            [LZCHINT title:@"发送成功" type:LZCSuccess duration:2 places:HINT_PLACES callBack:NULL];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            });

        }
    }];
}

- (void)sendMedalAction:(id)sender {
    UIButton *itemBtn = (UIButton *)sender;
    itemBtn.enabled = NO;
    itemBtn.alpha = 0.65;
    
    NSString *filename = [PATH_DOC_CHILMEDAL stringByAppendingPathComponent:chilIdMedal_];
    [self.medalPlistArr[itemBtn.tag] setObject:@"0" forKey:@"operateNumb"];
    [self.medalPlistArr writeToFile:filename atomically:YES];
    
    NSString *childId = self.chilIdStr;
    NSString *medalId = [NSString stringWithFormat:@"%ld",(long)itemBtn.tag+1];
    [myInfoHelper_ sendMedalInfoForChildId:childId medalId:medalId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
        }else{
            NSLog(@"测试颁发勋章结果：%@",result);
        }
    }];
}

- (void)backBeforeVc {
    [self releaseResource];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)browseFullText:(NSNotification *)notification {
    BN_CommentXQViewController *commentXQVC = [[BN_CommentXQViewController alloc]init];
    commentXQVC.receiveArr = notification.object;
    [self.navigationController pushViewController:commentXQVC animated:YES];
}

- (void)lookBeforeInfoAction {
    
    // 列表显示与消失
    if (self.commentTableView.hidden) {
        self.commentTableView.hidden = NO;
        upDownImgView.image = [UIImage imageNamed:@"comment_jiantou_down"];
        
        // 查看周评列表
        if (!browseCommentData_) {
            browseCommentData_ = [[BN_Mine_TeacherBrowseCommentData alloc]initWithChilId:self.chilIdStr];
        }
        [browseCommentData_ toReloadList:^(BOOL isReload) {
            if (isReload) {
                [self.commentTableView reloadData];
            }
        }];
        self.commentTableView.dataSource = browseCommentData_;
        self.commentTableView.delegate = browseCommentData_;

    }else {
        self.commentTableView.hidden = YES;
        upDownImgView.image = [UIImage imageNamed:@"comment_jiantou_up"];
    }

    // 键盘消失
    [self.cpTextView resignFirstResponder];
}

#pragma mark
#pragma mark 判断当前为星期几
+ (NSString *)getWeekday
{
    NSDate *date = [NSDate date];
    NSDateComponents *componets = [[NSCalendar autoupdatingCurrentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
    NSString *weekday = [self getWeekdayWithNumber:[componets weekday]];
    return weekday;
}

// 1代表星期日、如此类推
+ (NSString *)getWeekdayWithNumber:(NSInteger)number
{
    switch (number) {
        case 1:
            return @"星期日";
            break;
        case 2:
            return @"星期一";
            break;
        case 3:
            return @"星期二";
            break;
        case 4:
            return @"星期三";
            break;
        case 5:
            return @"星期四";
            break;
        case 6:
            return @"星期五";
            break;
        case 7:
            return @"星期六";
            break;
        default:
            return @"";
            break;
    }
}

#pragma mark 判断两个日期之间的间隔
- (NSInteger)dataSpace:(NSString *)dataStr {
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
    NSDate* toDate = [dateFormatter dateFromString:dataStr];
    NSDate *startDate = [[ NSDate alloc] init ];
    NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSGregorianCalendar ];
    NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit;
    
    NSDateComponents *cps = [ chineseClendar components:unitFlags fromDate:startDate toDate:toDate options:0];
    NSInteger diffDay = [cps day];
    return diffDay;
    /* how to use 
    NSInteger diffYear = [cps year];
    NSInteger diffMon = [cps month];
    NSInteger diffDay = [cps day];
    NSInteger diffHour = [cps hour];
    NSInteger diffMin = [cps minute];
    NSInteger diffSec = [cps second];*/
}

#pragma mark 资源
- (void)releaseResource {
    COUNT_ = 0;
    [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"MINE_TEACHER_IS_SENDMEDAL"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    self.cpTextView.delegate = nil;
    self.commentTableView.delegate = nil;
    self.commentTableView.dataSource = nil;
    
    myInfoHelper_ = nil;
    browseCommentData_ = nil;
    cpTextDelegate_ = nil;
    
}

- (void)dealloc
{
    [self releaseResource];
    NSLog(@"教师颁勋章、写评语界面 释放...");
}

@end
